package cn.xiaou.view;

import java.awt.Point;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JFrame;

public class JFrameMove extends MouseAdapter{
	private static Point origin = new Point();
	private JFrame frame;
	public JFrameMove(JFrame frame) {
		this.frame = frame;
	}
	public void mousePressed(MouseEvent e) {
		origin.x = e.getX();
		origin.y = e.getY();
	}
	public void mouseDragged(MouseEvent e) {
		// 当鼠标拖动时获取窗口当前位置
		Point p = frame.getLocation();
		// 设置窗口的位置
		// 窗口当前的位置 + 鼠标当前在窗口的位置 - 鼠标按下的时候在窗口的位置
		frame.setLocation(p.x + e.getX() - origin.x, p.y + e.getY()- origin.y);
	}
}
